package com.project.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.entity.UserEntity;
import com.project.entity.UserRecordEntity;
import com.project.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("user")
public class UserController {

    @Autowired
    private IUserService userService;

    @RequestMapping("findByItem")
    public IPage<UserEntity> findByItem(int pageNO, int status,int pageSize) {
        IPage<UserEntity> byItem = userService.findByItem(pageNO, status, pageSize);
        System.out.println("byItem = " + byItem.getRecords());
        return byItem;
    }

    @RequestMapping("findById")
    public UserRecordEntity findById(long id) {
        return userService.findById(id);
    }


    @RequestMapping("findHistory")
    public List<UserRecordEntity> findByHistory(long userRef) {
        return userService.findByHistory(userRef);
    }

    @RequestMapping("updateStatus")
    public String  updateStatus(long userRef, int status,String cause) {
        userService.updateStatus(userRef,status,cause);
        return "ok";
    }
}
